#ifndef PUZZLEWINDOW_H
#define PUZZLEWINDOW_H

#include <QWidget>
#include <QPushButton>
#include <QGridLayout>
#include<QSoundEffect>
#include <QMainWindow>
#include <QPixmap>
#include <QVector>
#include <QGridLayout>
#include <QShowEvent>
#include "gamecontrolwindow.h"
#include "welcomewindow.h"


class PuzzleWindow : public QWidget
{
    Q_OBJECT

public:
    explicit PuzzleWindow(int difficulty = 3, WelcomeWindow *welcomeWindow=nullptr, QWidget *parent = nullptr);
        void setDifficulty(int newDifficulty);



private slots:
    void handleButtonClick();
    void shuffle();
    bool checkPuzzleSolved();


    void setInteractionEnabled(bool enabled);


private:

    WelcomeWindow*welcomeWindow;


    GameControlWindow *controlWindow;

    QVector<QPixmap> imageParts; // 添加图片分片存储
    QPixmap originalImage;       // 原始完整图片

    QSoundEffect soundEffect;
    QSoundEffect succeedSound;


    int m_difficulty;
    QVector<QPushButton*> buttons;

    int emptyRow;
    int emptyCol;

     QGridLayout *gridLayout; // 添加布局成员变量
    void swapButtons(int row1, int col1, int row2, int col2);

 signals:
    void destroyed();
    void returnToWelcome();

       protected:
    // 修正事件处理函数声明
    void closeEvent(QCloseEvent *event) override;
    void showEvent(QShowEvent *event) override;


};

#endif // PUZZLEWINDOW_H
